//
//  NotLikeToastController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/22.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "NotLikeToastController.h"
#import "ReportArticleToastController.h"

@interface NotLikeToastController ()<UITableViewDelegate,UITableViewDataSource>
/**listView*/
@property (nonatomic,strong)UITableView*listView;
/**数据源*/
@property (nonatomic,strong)NSMutableArray*dataSoure;

@end

@implementation NotLikeToastController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHidenNaviBar = YES;
    [self createUI];
}
-(void)createUI{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15,15)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.view.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.view.layer.mask = maskLayer;

    UIView * headerView = [self createHeaderView];
    headerView.backgroundColor = KWhiteColor;
    
    UIView * footView = [self createFootView];
    footView.backgroundColor = KWhiteColor;

    
    [self.view addSubview:headerView];
    [self.view addSubview:footView];
    [self.view addSubview:self.listView];

    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    [footView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];

    [self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(headerView.mas_bottom);
        make.bottom.mas_equalTo(footView.mas_top);
    }];

}
#pragma mark ---UITableViewDelegate,UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSoure.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
//    cell.textLabel.textColor = UIColorFromRGB(0x273323);
//    cell.textLabel.font = SYSTEMFONT(14);
    cell.textLabel.attributedText = self.dataSoure[indexPath.row];
    
    UIImageView * image = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"more")];
    [cell.contentView addSubview:image];
    
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
    }];
    
    if (indexPath.row == self.dataSoure.count - 1) {
        image.hidden = NO;
    }else{
        image.hidden = YES;
    }
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 350/(self.dataSoure.count + 2);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.dataSoure.count - 1 == indexPath.row) {
        [self reportArticleToast];
    }else{
        [self backBtnClicked];
    }
}
-(UITableView*)listView{
    if(!_listView){
        _listView=[UITableView new];
        _listView.delegate =self;
        _listView.dataSource = self;
        _listView.scrollEnabled = NO;
        _listView.rowHeight = UITableViewAutomaticDimension;
        _listView.estimatedRowHeight = 44.0f;

        [_listView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
        _listView.separatorColor = SeparatorColor;
        _listView.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
    }
    return _listView;
}
-(NSMutableArray *)dataSoure{
    if (!_dataSoure) {
        NSMutableAttributedString * string1 = [self getItemTitle:@"拉黑作者" TwoString:@"：XXX的内容"];
        NSMutableAttributedString * string2 = [self getItemTitle:@"不想看" TwoString:@"：XXX的内容"];
        NSMutableAttributedString * string3 = [self getItemTitle:@"不想看" TwoString:@"：XXX的内容"];
        NSMutableAttributedString * string4 = [self getItemTitle:@"不想看" TwoString:@"：XXX的内容"];
        NSMutableAttributedString * string5 = [self getItemTitle:@"举报文章问题" TwoString:@""];

        _dataSoure =[[NSMutableArray alloc] initWithObjects:string1,string2,string3,string4,string5, nil];
    }
    return _dataSoure;
}
-(NSMutableAttributedString *)getItemTitle:(NSString *)oneStr TwoString:(NSString *)twostring{
    NSMutableAttributedString * string = [TitleTool getAttributeStringLineSpacing:0 title:oneStr titleColor:UIColorFromRGB(0x273323) titleFont:PingFangSC_Medium(14)];
    
    [string makeAttributeStringAdd:twostring Attribute:^(NSMutableDictionary * _Nonnull attributes) {
        attributes.Color(UIColorFromRGB(0x273323));
        [attributes setValue:PingFangSC_Regular(14) forKey:NSFontAttributeName];
    }];
    
    return string;

}
-(UIView *)createHeaderView{
    UIView * view = UIView.new;
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"取消" forState:UIControlStateNormal];
    button.titleLabel.font = PingFangSC_Regular(14);
    [button setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateNormal];
    [button setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateNormal];
    kWeakSelf(weakSelf);
    [button addActionHandler:^{
        [weakSelf backBtnClicked];
    }];

    UILabel * label = UILabel.new;
    label.text = @"不喜欢";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = PingFangSC_Medium(16);
    label.textColor = UIColorFromRGB(0x273323);
    
    [view addSubview:button];
    [view addSubview:label];

    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(0);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}
-(UIView *)createFootView{
    UIView * view = UIView.new;
    
    
    UILabel * label = UILabel.new;
    label.text = @"完成";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = PingFangSC_Medium(16);
    label.textColor = UIColorFromRGB(0x273323);
    
    [view addSubview:label];
    
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backBtnClicked)]];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}

/**
 举报
 */
-(void)reportArticleToast{
    PresentationObject * object = [PresentationObject sharedPresentationObject];
    object.subViewFrame = CGRectMake(0, 100, KScreenWidth, KScreenHeight-100);
    ReportArticleToastController * vc = [ReportArticleToastController new];
    kWeakSelf(weakSelf);
    vc.backBlck = ^{
        [weakSelf backBtnClicked];
    };
    [object showPresentingViewController:self PresentedViewController:[[BasseNavigationController alloc]initWithRootViewController:vc]];

}
@end
